package com.sx.pipeline.ui.wallet.withdraw.record

import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.android.material.tabs.TabLayoutMediator
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.databinding.ActWithdrawDetailBinding
import com.sx.pipeline.ui.wallet.withdraw.WithdrawVM


/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: 提现明细
 */
@Route(path = RoutePath.Wallet.WITHDRAW_DETAILS)
class WithdrawRecordActivity : CYDataBindingBaseActivity<ActWithdrawDetailBinding, WithdrawVM>(R.layout.act_withdraw_detail) {
    private lateinit var mAdapter:WithdrawRecordPageAdapter
    override fun initData() {
        mBinding.titleBar.leftView.setOnClickListener {
            finish()
        }
        initPager()
    }

    /**
     * 初始化ViewPager
     */
    private fun initPager() {
        if (mBinding.viewpager.adapter == null) {
            mAdapter = WithdrawRecordPageAdapter(
                mViewModel.getWithdrawTabsList(),mViewModel.getWithdrawTabsId(), supportFragmentManager, lifecycle)
        }
        mBinding.viewpager.adapter = mAdapter
        mBinding.viewpager.offscreenPageLimit=mViewModel.getWithdrawTabsList().size
        mBinding.viewpager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {

            }
        })

        //绑定tabLayout和viewPager
        TabLayoutMediator(
            mBinding.tabLayout, mBinding.viewpager,
            true, true
        ) { tab, position ->
            tab.text = mViewModel.getWithdrawTabsList()[position]
        }.attach()
    }

}